import 'package:flutter/material.dart';

class ColorfulButton extends StatefulWidget {

  final String buttonName;
  final Function onTap;


  ColorfulButton(this.buttonName, this.onTap);

  @override
  _ColorfulButtonState createState() => _ColorfulButtonState();
}

class _ColorfulButtonState extends State<ColorfulButton> {
  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: () {
        widget.onTap();
      },
      child: Container(
        height: 45,
        margin: EdgeInsets.fromLTRB(10, 6, 10, 2),
        alignment: Alignment.center,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.all(Radius.circular(6)),
            gradient: LinearGradient(
              //渐变位置
                begin: Alignment.topRight, //右上
                end: Alignment.bottomLeft, //左下
                stops: [
                  0.0,
                  1.0
                ], //[渐变起始点, 渐变结束点]
                //渐变颜色[始点颜色, 结束颜色]
                colors: [
                  Color.fromRGBO(56, 160, 253, 0.9),
                  Color.fromRGBO(26, 103, 250, 0.9)
                ])),
        child: FractionallySizedBox(
            alignment: Alignment.center,
            widthFactor: 1,
            child: Container(
              alignment: Alignment.center,
              child: Text(
                widget.buttonName,
                style: TextStyle(color: Colors.white),
              ),
            )),
      ),
    );
  }
}

